#ifndef LOCALCONFIG_H
#define LOCALCONFIG_H

#include <QCoreApplication>
#include <QDate>
#include <QDateTime>
#include <QDebug>
#include <QMutex>
#include <QObject>
#include <QSettings>
#include <QTime>

class LocalConfig : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString plc_Port READ plc_Port WRITE setPlc_Port NOTIFY plc_PortChanged FINAL)
    Q_PROPERTY(QString plc_Baudrate READ plc_Baudrate WRITE setPlc_Baudrate NOTIFY
                   plc_BaudrateChanged FINAL)
    Q_PROPERTY(
        QString plc_Databit READ plc_Databit WRITE setPlc_Databit NOTIFY plc_DatabitChanged FINAL)
    Q_PROPERTY(QString plc_Parity READ plc_Parity WRITE setPlc_Parity NOTIFY plc_ParityChanged FINAL)
    Q_PROPERTY(
        QString plc_Stopbit READ plc_Stopbit WRITE setPlc_Stopbit NOTIFY plc_StopbitChanged FINAL)

    Q_PROPERTY(QString printer_Port READ printer_Port WRITE setPrinter_Port NOTIFY
                   printer_PortChanged FINAL)
    Q_PROPERTY(QString printer_Baudrate READ printer_Baudrate WRITE setPrinter_Baudrate NOTIFY
                   printer_BaudrateChanged FINAL)
    Q_PROPERTY(QString printer_Databit READ printer_Databit WRITE setPrinter_Databit NOTIFY
                   printer_DatabitChanged FINAL)
    Q_PROPERTY(QString printer_Parity READ printer_Parity WRITE setPrinter_Parity NOTIFY
                   printer_ParityChanged FINAL)
    Q_PROPERTY(QString printer_Stopbit READ printer_Stopbit WRITE setPrinter_Stopbit NOTIFY
                   printer_StopbitChanged FINAL)

    Q_PROPERTY(QString scanner_Port READ scanner_Port WRITE setScanner_Port NOTIFY
                   scanner_PortChanged FINAL)
    Q_PROPERTY(QString scanner_Baudrate READ scanner_Baudrate WRITE setScanner_Baudrate NOTIFY
                   scanner_BaudrateChanged FINAL)
    Q_PROPERTY(QString scanner_Databit READ scanner_Databit WRITE setScanner_Databit NOTIFY
                   scanner_DatabitChanged FINAL)
    Q_PROPERTY(QString scanner_Parity READ scanner_Parity WRITE setScanner_Parity NOTIFY
                   scanner_ParityChanged FINAL)
    Q_PROPERTY(QString scanner_Stopbit READ scanner_Stopbit WRITE setScanner_Stopbit NOTIFY
                   scanner_StopbitChanged FINAL)

    // 当前语言类型
    Q_PROPERTY(int CurrentLanguage READ CurrentLanguage WRITE setCurrentLanguage NOTIFY
                   CurrentLanguageChanged FINAL)
    // 当前打印机类型
    Q_PROPERTY(int CurrentPrinter READ CurrentPrinter WRITE setCurrentPrinter NOTIFY
                   CurrentPrinterChanged FINAL)

    // 二维码类型
    Q_PROPERTY(int Current_QR_Code READ Current_QR_Code WRITE setCurrent_QR_Code NOTIFY Current_QR_CodeChanged FINAL)

public:
    static LocalConfig *getInstance(QObject *parent);
    static LocalConfig *m_instance;
    static QMutex m_mutex;

    void init_Data();
    void save_Data();

    QString plc_Port() const;
    void setPlc_Port(const QString &newPlc_Port);

    QString plc_Baudrate() const;
    void setPlc_Baudrate(const QString &newPlc_Baudrate);

    QString plc_Databit() const;
    void setPlc_Databit(const QString &newPlc_Databit);

    QString plc_Parity() const;
    void setPlc_Parity(const QString &newPlc_Parity);

    QString plc_Stopbit() const;
    void setPlc_Stopbit(const QString &newPlc_Stopbit);

    QString printer_Port() const;
    void setPrinter_Port(const QString &newPrinter_Port);

    QString printer_Baudrate() const;
    void setPrinter_Baudrate(const QString &newPrinter_Baudrate);

    QString printer_Databit() const;
    void setPrinter_Databit(const QString &newPrinter_Databit);

    QString printer_Parity() const;
    void setPrinter_Parity(const QString &newPrinter_Parity);

    QString printer_Stopbit() const;
    void setPrinter_Stopbit(const QString &newPrinter_Stopbit);

    QString scanner_Port() const;
    void setScanner_Port(const QString &newScanner_Port);

    QString scanner_Baudrate() const;
    void setScanner_Baudrate(const QString &newScanner_Baudrate);

    QString scanner_Databit() const;
    void setScanner_Databit(const QString &newScanner_Databit);

    QString scanner_Parity() const;
    void setScanner_Parity(const QString &newScanner_Parity);

    QString scanner_Stopbit() const;
    void setScanner_Stopbit(const QString &newScanner_Stopbit);

    int CurrentLanguage() const;
    void setCurrentLanguage(int newCurrentLanguage);

    int CurrentPrinter() const;
    void setCurrentPrinter(int newCurrentPrinter);

    int Current_QR_Code() const;
    void setCurrent_QR_Code(int newCurrent_QR_Code);

private:
    LocalConfig(QObject *parent = nullptr);
    ~LocalConfig();
    LocalConfig(const LocalConfig &) = delete;
    LocalConfig &operator=(const LocalConfig) = delete;
    QString m_plc_Port;

    QString m_plc_Baudrate;

    QString m_plc_Databit;

    QString m_plc_Parity;

    QString m_plc_Stopbit;

    QString m_printer_Port;

    QString m_printer_Baudrate;

    QString m_printer_Databit;

    QString m_printer_Parity;

    QString m_printer_Stopbit;

    QString m_scanner_Port;

    QString m_scanner_Baudrate;

    QString m_scanner_Databit;

    QString m_scanner_Parity;

    QString m_scanner_Stopbit;

    int m_CurrentLanguage;

    int m_CurrentPrinter;

    int m_Current_QR_Code;

signals:
    void plc_PortChanged();
    void plc_BaudrateChanged();
    void plc_DatabitChanged();
    void plc_ParityChanged();
    void plc_StopbitChanged();
    void printer_PortChanged();
    void printer_BaudrateChanged();
    void printer_DatabitChanged();
    void printer_ParityChanged();
    void printer_StopbitChanged();
    void scanner_PortChanged();
    void scanner_BaudrateChanged();
    void scanner_DatabitChanged();
    void scanner_ParityChanged();
    void scanner_StopbitChanged();
    void CurrentLanguageChanged();
    void CurrentPrinterChanged();
    void Current_QR_CodeChanged();
};

#endif // LOCALCONFIG_H
